package com.sunmouse.toolkit.fragment.ftp;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.fragment.BaseFragment;
import com.sunmouse.toolkit.ftp.FTPHelper;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class FtpMenuFragment extends BaseFragment {


    @BindView(R.id.menu_container)
    FrameLayout menuContainer;
    Unbinder unbinder;

    private ArrayList<Fragment> fragments;
    private FTPHelper mFtp;


    public FtpMenuFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_ftp_menu, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void init() {
        mFtp= FTPHelper.getInstance(getActivity());
        fragments = new ArrayList<>();
        fragments.add(new FtpConnectFragment());
        fragments.add(new FtpInfoFragment());
        mManager = getChildFragmentManager();
        mManager.beginTransaction()
                .add(R.id.menu_container, fragments.get(0))
                .commit();
        if (mFtp.getClient().isConnected()) {
            mManager.beginTransaction()
                    .replace(R.id.menu_container, fragments.get(1))
                    .commit();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
